package com.lh_travel.lohas.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lh_travel.lohas.R;
import com.lh_travel.lohas.domain.Comment;

import java.util.ArrayList;
import java.util.List;

public class MyExpandableAdapter extends BaseExpandableListAdapter {

    private List<Comment> groupArray;
    private Context mContext;

    public MyExpandableAdapter(Context context, List<Comment> groupArray) {
        mContext = context;
        this.groupArray = groupArray;

    }

    @Override
    public int getGroupCount() {
        return groupArray.size();
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        return 1;
    }

    @Override
    public Object getGroup(int groupPosition) {
        return groupArray.get(groupPosition);
    }

    @Override
    public Object getChild(int groupPosition, int childPosition) {
        return groupArray.get(groupPosition).content;
    }

    @Override
    public long getGroupId(int groupPosition) {
        return groupPosition;
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
        return childPosition;
    }

    @Override
    public boolean hasStableIds() {
        return true;
    }

    @Override
    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
        View view = convertView;
        GroupHolder holder = null;
        if (view == null) {
            holder = new GroupHolder();
            view = LayoutInflater.from(mContext).inflate(R.layout.item_quest, null);

            holder.tv_city = (TextView) view.findViewById(R.id.tv_city);
            view.setTag(holder);
        } else {
            holder = (GroupHolder) view.getTag();
        }

        holder.tv_city.setText(groupArray.get(groupPosition).title);

        return view;
    }

    @Override
    public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
        View view = convertView;
        ChildHolder holder = null;
        if (view == null) {
            holder = new ChildHolder();
            view = LayoutInflater.from(mContext).inflate(R.layout.item_quest2, null);
            holder.childName = (TextView) view.findViewById(R.id.tv_name);

            view.setTag(holder);
        } else {
            holder = (ChildHolder) view.getTag();
        }

        holder.childName.setText(groupArray.get(groupPosition).content);

        return view;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return true;
    }

    class GroupHolder {
        public TextView tv_city;
    }

    class ChildHolder {
        public TextView childName;

    }
}
